﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace BskLeague.Models
{
    public class Player
    {
        public int PlayerId { get; set; }
        public string PlayerName { get; set; }
        public string PlayerSurname { get; set; }
        public string Photo { get; set; }
        public Team Team
        {
            get
            {
                var _db = new BskLeagueDB();
                //wybierz "najbardziej aktywny" niezakończony sezon
                Season season = _db.Seasons.OrderByDescending(s => s.SeasonId).FirstOrDefault(s => s.StatusId < 3); 

                var stp = _db.SeasonTeamPlayers.Where(s => s.PlayerId == PlayerId).ToList();

                if (stp.Find(s => s.Season == season) == null)
                    return null;
                else
                    return stp.Find(s => s.Season == season).Team;
            }

        }
        public short Height { get; set; }
        public short Weight { get; set; }
        public short PlayerNumber{ get; set; }
        public string Email { get; set; }
        public string About { get; set; }

        [DisplayFormat(DataFormatString = "{0:dd MMM yyyy}")]
        public DateTime Date {get; set;}

        public string UserName { get; set; }
        public virtual List<SeasonTeamPlayer> STPs { get; set; }

        public int? LicenceId {get; set;}
        public virtual Licence Licence { get; set; }
    }
}